//
// Created by 45595 on 2021/10/5.
//

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 30010;

struct Student{
    string id;
    int score,location,location_rank;
}stu[MAXN];

bool cmp(Student &a,Student &b);

int main() {
    freopen("../data/A1025.txt", "r", stdin);
    int N;
    cin>>N;
    int k,num=0;
    for(int i=1;i<=N;i++){
        cin>>k;
        num+=k;
        for(int j = num-k;j<num;j++){
            cin>>stu[j].id>>stu[j].score;
            stu[j].location = i;
        }
        sort(stu+num-k,stu+num,cmp);
        stu[num-k].location_rank = 1;
        for(int j=num-k+1;j<num;j++){
            if(stu[j].score==stu[j-1].score) stu[j].location_rank = stu[j-1].location_rank;
            else stu[j].location_rank = j+1-(num-k);
        }
    }

    sort(stu,stu+num,cmp);
    int r = 1;
    cout<<num<<endl;
    cout<<stu[0].id<<" "<<r<<" "<<stu[0].location<<" "<<stu[0].location_rank<<endl;
    for(int i=1;i<num;i++){
        if(stu[i].score==stu[i-1].score) cout<<stu[i].id<<" "<<r<<" "<<stu[i].location<<" "<<stu[i].location_rank<<endl;
        else{
            r = i+1;
            cout<<stu[i].id<<" "<<r<<" "<<stu[i].location<<" "<<stu[i].location_rank<<endl;
        }
    }

    return 0;
}

bool cmp(Student &a,Student &b){
    return a.score!=b.score?a.score>b.score:a.id<b.id;
}